package com.cb.web.wasf.sample.model;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import javax.persistence.PersistenceException;

/**
 * @author CBO
 */
public class PersistenceExceptionUtils {
    
    public static boolean isUniqueIndexViolation(PersistenceException persistenceException) {
        final Writer result = new StringWriter();
        final PrintWriter printWriter = new PrintWriter(result);
        persistenceException.printStackTrace(printWriter);
        if (result.toString().toUpperCase().contains("UNIQUE INDEX")) {
            return true;
        } else {
            return false;
        }
    }
    
}
